// Jesse James Outlaw
// Project LifeSync
// Allows users to make a checklist for the assisstance of their memories
#include "checklist.h"
#include "ui_checklist.h"
#include <QtGUI>
#include <QObject>
#include <fstream>
#include <QListWidget>

Checklist::Checklist(QWidget *parent) : QDialog(parent), checklistWindow(new Ui::Checklist)
{ 
    checklistWindow->setupUi(this);
    load();
    setFixedSize(341, 450);
}
void Checklist::on_addItemButton_clicked()
{
    if(checklistWindow->checkEntry->text() == (""))
    {
        QMessageBox mb;
        mb.setText("You cannot have a checklist item with no text attached.");
        mb.exec();
    }
    else if(checklistWindow->cb1->isVisible() == false)
    {
        checklistWindow->cb1->setVisible(true);                             // Makes cb visible
        checklistWindow->cb1->setText(checklistWindow->checkEntry->text()); // Sets cb text to user entered text
    }
    else if(checklistWindow->cb2->isVisible() == false)
    {
        checklistWindow->cb2->setVisible(true);
        checklistWindow->cb2->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb3->isVisible() == false)
    {
        checklistWindow->cb3->setVisible(true);
        checklistWindow->cb3->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb4->isVisible() == false)
    {
        checklistWindow->cb4->setVisible(true);
        checklistWindow->cb4->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb5->isVisible() == false)
    {
        checklistWindow->cb5->setVisible(true);
        checklistWindow->cb5->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb6->isVisible() == false)
    {
        checklistWindow->cb6->setVisible(true);
        checklistWindow->cb6->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb7->isVisible() == false)
    {
        checklistWindow->cb7->setVisible(true);
        checklistWindow->cb7->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb8->isVisible() == false)
    {
        checklistWindow->cb8->setVisible(true);
        checklistWindow->cb8->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb9->isVisible() == false)
    {
        checklistWindow->cb9->setVisible(true);
        checklistWindow->cb9->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb10->isVisible() == false)
    {
        checklistWindow->cb10->setVisible(true);
        checklistWindow->cb10->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb11->isVisible() == false)
    {
        checklistWindow->cb11->setVisible(true);
        checklistWindow->cb11->setText(checklistWindow->checkEntry->text());
    }
    else if(checklistWindow->cb12->isVisible() == false)
    {
        checklistWindow->cb12->setVisible(true);
        checklistWindow->cb12->setText(checklistWindow->checkEntry->text());
    }
    else
    {
        QMessageBox mb;
        mb.setText("You can only have a maximum of one dozen checklist items.");
        mb.exec();
    }
    checklistWindow->checkEntry->clear();
}
//itterate through checklistLayout and delete all checkboxes where checked == true
void Checklist::on_remItemButton_clicked()
{
    if(checklistWindow->cb1->isChecked() == true)
    {
        checklistWindow->cb1->setVisible(false); // Makes cb invisible
        checklistWindow->cb1->setChecked(false); // Unchecks cb if checked
        checklistWindow->cb1->setText("");       // Clears text attached to cb
    }
    if(checklistWindow->cb2->isChecked() == true)
    {
        checklistWindow->cb2->setVisible(false);
        checklistWindow->cb2->setChecked(false);
        checklistWindow->cb2->setText("");
    }
    if(checklistWindow->cb3->isChecked() == true)
    {
        checklistWindow->cb3->setVisible(false);
        checklistWindow->cb3->setChecked(false);
        checklistWindow->cb3->setText("");
    }
    if(checklistWindow->cb4->isChecked() == true)
    {
        checklistWindow->cb4->setVisible(false);
        checklistWindow->cb4->setChecked(false);
        checklistWindow->cb4->setText("");
    }
    if(checklistWindow->cb5->isChecked() == true)
    {
        checklistWindow->cb5->setVisible(false);
        checklistWindow->cb5->setChecked(false);
        checklistWindow->cb5->setText("");
    }
    if(checklistWindow->cb6->isChecked() == true)
    {
        checklistWindow->cb6->setVisible(false);
        checklistWindow->cb6->setChecked(false);
        checklistWindow->cb6->setText("");
    }
    if(checklistWindow->cb7->isChecked() == true)
    {
        checklistWindow->cb7->setVisible(false);
        checklistWindow->cb7->setChecked(false);
        checklistWindow->cb7->setText("");
    }
    if(checklistWindow->cb8->isChecked() == true)
    {
        checklistWindow->cb8->setVisible(false);
        checklistWindow->cb8->setChecked(false);
        checklistWindow->cb8->setText("");
    }
    if(checklistWindow->cb9->isChecked() == true)
    {
        checklistWindow->cb9->setVisible(false);
        checklistWindow->cb9->setChecked(false);
        checklistWindow->cb9->setText("");
    }
    if(checklistWindow->cb10->isChecked() == true)
    {
        checklistWindow->cb10->setVisible(false);
        checklistWindow->cb10->setChecked(false);
        checklistWindow->cb10->setText("");
    }
    if(checklistWindow->cb11->isChecked() == true)
    {
        checklistWindow->cb11->setVisible(false);
        checklistWindow->cb11->setChecked(false);
        checklistWindow->cb11->setText("");
    }
    if(checklistWindow->cb12->isChecked() == true)
    {
        checklistWindow->cb12->setVisible(false);
        checklistWindow->cb12->setChecked(false);
        checklistWindow->cb12->setText("");
    }
}
void Checklist::save()
{
    QSettings ChecklistSettings("LifeSync", "Project LifeSync");

    ChecklistSettings.setValue("cbhide1", checklistWindow->cb1->isVisible()); // Save Visibility
    ChecklistSettings.setValue("cbhide2", checklistWindow->cb2->isVisible());
    ChecklistSettings.setValue("cbhide3", checklistWindow->cb3->isVisible());
    ChecklistSettings.setValue("cbhide4", checklistWindow->cb4->isVisible());
    ChecklistSettings.setValue("cbhide5", checklistWindow->cb5->isVisible());
    ChecklistSettings.setValue("cbhide6", checklistWindow->cb6->isVisible());
    ChecklistSettings.setValue("cbhide7", checklistWindow->cb7->isVisible());
    ChecklistSettings.setValue("cbhide8", checklistWindow->cb8->isVisible());
    ChecklistSettings.setValue("cbhide9", checklistWindow->cb9->isVisible());
    ChecklistSettings.setValue("cbhide10", checklistWindow->cb10->isVisible());
    ChecklistSettings.setValue("cbhide11", checklistWindow->cb11->isVisible());
    ChecklistSettings.setValue("cbhide12", checklistWindow->cb12->isVisible());

    ChecklistSettings.setValue("check1", checklistWindow->cb1->isChecked()); // Save Checked Value
    ChecklistSettings.setValue("check2", checklistWindow->cb2->isChecked());
    ChecklistSettings.setValue("check3", checklistWindow->cb3->isChecked());
    ChecklistSettings.setValue("check4", checklistWindow->cb4->isChecked());
    ChecklistSettings.setValue("check5", checklistWindow->cb5->isChecked());
    ChecklistSettings.setValue("check6", checklistWindow->cb6->isChecked());
    ChecklistSettings.setValue("check7", checklistWindow->cb7->isChecked());
    ChecklistSettings.setValue("check8", checklistWindow->cb8->isChecked());
    ChecklistSettings.setValue("check9", checklistWindow->cb9->isChecked());
    ChecklistSettings.setValue("check10", checklistWindow->cb10->isChecked());
    ChecklistSettings.setValue("check11", checklistWindow->cb11->isChecked());
    ChecklistSettings.setValue("check12", checklistWindow->cb12->isChecked());

    ChecklistSettings.setValue("cbnote1", checklistWindow->cb1->text()); // Save Text of Checkbox
    ChecklistSettings.setValue("cbnote2", checklistWindow->cb2->text());
    ChecklistSettings.setValue("cbnote3", checklistWindow->cb3->text());
    ChecklistSettings.setValue("cbnote4", checklistWindow->cb4->text());
    ChecklistSettings.setValue("cbnote5", checklistWindow->cb5->text());
    ChecklistSettings.setValue("cbnote6", checklistWindow->cb6->text());
    ChecklistSettings.setValue("cbnote7", checklistWindow->cb7->text());
    ChecklistSettings.setValue("cbnote8", checklistWindow->cb8->text());
    ChecklistSettings.setValue("cbnote9", checklistWindow->cb9->text());
    ChecklistSettings.setValue("cbnote10", checklistWindow->cb10->text());
    ChecklistSettings.setValue("cbnote11", checklistWindow->cb11->text());
    ChecklistSettings.setValue("cbnote12", checklistWindow->cb12->text());
}
void Checklist::load()
{
    QSettings ChecklistSettings("LifeSync", "Project LifeSync");

    checklistWindow->cb1->setVisible(ChecklistSettings.value("cbhide1").toBool());  // Load Visibility
    checklistWindow->cb2->setVisible(ChecklistSettings.value("cbhide2").toBool());
    checklistWindow->cb3->setVisible(ChecklistSettings.value("cbhide3").toBool());
    checklistWindow->cb4->setVisible(ChecklistSettings.value("cbhide4").toBool());
    checklistWindow->cb5->setVisible(ChecklistSettings.value("cbhide5").toBool());
    checklistWindow->cb6->setVisible(ChecklistSettings.value("cbhide6").toBool());
    checklistWindow->cb7->setVisible(ChecklistSettings.value("cbhide7").toBool());
    checklistWindow->cb8->setVisible(ChecklistSettings.value("cbhide8").toBool());
    checklistWindow->cb9->setVisible(ChecklistSettings.value("cbhide9").toBool());
    checklistWindow->cb10->setVisible(ChecklistSettings.value("cbhide10").toBool());
    checklistWindow->cb11->setVisible(ChecklistSettings.value("cbhide11").toBool());
    checklistWindow->cb12->setVisible(ChecklistSettings.value("cbhide12").toBool());

    checklistWindow->cb1->setChecked(ChecklistSettings.value("check1").toBool()); // Load Checked Value
    checklistWindow->cb2->setChecked(ChecklistSettings.value("check2").toBool());
    checklistWindow->cb3->setChecked(ChecklistSettings.value("check3").toBool());
    checklistWindow->cb4->setChecked(ChecklistSettings.value("check4").toBool());
    checklistWindow->cb5->setChecked(ChecklistSettings.value("check5").toBool());
    checklistWindow->cb6->setChecked(ChecklistSettings.value("check6").toBool());
    checklistWindow->cb7->setChecked(ChecklistSettings.value("check7").toBool());
    checklistWindow->cb8->setChecked(ChecklistSettings.value("check8").toBool());
    checklistWindow->cb9->setChecked(ChecklistSettings.value("check9").toBool());
    checklistWindow->cb10->setChecked(ChecklistSettings.value("check10").toBool());
    checklistWindow->cb11->setChecked(ChecklistSettings.value("check11").toBool());
    checklistWindow->cb12->setChecked(ChecklistSettings.value("check12").toBool());

    checklistWindow->cb1->setText(ChecklistSettings.value("cbnote1").toString()); // Load Text of Checkbox
    checklistWindow->cb2->setText(ChecklistSettings.value("cbnote2").toString());
    checklistWindow->cb3->setText(ChecklistSettings.value("cbnote3").toString());
    checklistWindow->cb4->setText(ChecklistSettings.value("cbnote4").toString());
    checklistWindow->cb5->setText(ChecklistSettings.value("cbnote5").toString());
    checklistWindow->cb6->setText(ChecklistSettings.value("cbnote6").toString());
    checklistWindow->cb7->setText(ChecklistSettings.value("cbnote7").toString());
    checklistWindow->cb8->setText(ChecklistSettings.value("cbnote8").toString());
    checklistWindow->cb9->setText(ChecklistSettings.value("cbnote9").toString());
    checklistWindow->cb10->setText(ChecklistSettings.value("cbnote10").toString());
    checklistWindow->cb11->setText(ChecklistSettings.value("cbnote11").toString());
    checklistWindow->cb12->setText(ChecklistSettings.value("cbnote12").toString());
}
void Checklist::on_Close_clicked()
{
    save();
    Checklist::close();
}

void Checklist::on_selectAll_clicked()
{
    checklistWindow->cb1->setChecked(true);
    checklistWindow->cb2->setChecked(true);
    checklistWindow->cb3->setChecked(true);
    checklistWindow->cb4->setChecked(true);
    checklistWindow->cb5->setChecked(true);
    checklistWindow->cb6->setChecked(true);
    checklistWindow->cb7->setChecked(true);
    checklistWindow->cb8->setChecked(true);
    checklistWindow->cb9->setChecked(true);
    checklistWindow->cb10->setChecked(true);
    checklistWindow->cb11->setChecked(true);
    checklistWindow->cb12->setChecked(true);
}
